﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Net.Mail;
using System.Drawing;

public partial class Contacto : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void EnviarCorreo(string Nombre, string Email, string Asunto, string Mensaje)
    {
        if (Page.IsValid)
        {
            string to = ConfigurationManager.AppSettings["To"];
            MailMessage mail = new MailMessage();
            mail.To.Add(new MailAddress(to));
            mail.From = new MailAddress(Email, Nombre);
            mail.Subject = Asunto + " " + Email;
            mail.Body = Mensaje + "\n\n" + Nombre + "\n" + Email;

            SmtpClient _smtp = new SmtpClient();
            _smtp.Send(mail);

            LimpiarCampos();
            lbl_aviso.BackColor = Color.Transparent;
        }
        else
        {
            lbl_aviso.Text = "No ha escrito correctamente el captcha";
            lbl_aviso.BackColor= Color.Red;
        }
    }

  
    protected void botonEnviar_Click(object sender, EventArgs e)
    {
       EnviarCorreo(Nombre.Text,
                       Email.Text,
                          Asunto.Text,
                            Mensaje.Text);
    }  
    private void LimpiarCampos()
    {
        Nombre.Text = "";
        Email.Text = "";
        Asunto.Text = "";
        Mensaje.Text = "";
        lbl_aviso.Text = "";
    }
  
}